<template>
  <div class="h-full w-full flex justify-center items-center">
    <!-- <el-form :model="form" class="p-4" style="width: 360px">
      <el-form-item label="用户名">
        <el-input v-model="form.username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.password"></el-input>
      </el-form-item>
      <el-form-item>
        <div class="text-right">
            <el-button type="primary" @click="onLogin">登录</el-button>
        </div>
      </el-form-item>
    </el-form> -->
    <el-card class="box-card" style="margin-top: -96px">
      <div slot="header" class="clearfix">
        <span class="login-title">🔐接口管理系统</span>
      </div>
      <div class="login-form">
        <el-form :model="form" :rules="loginRules" ref="loginForm">
          <el-form-item prop="username">
            <el-input
              type="text"
              v-model="form.username"
              name="username"
              autocomplete="on"
              placeholder="请输入用户名"
            >
              <template slot="prepend"
                ><i style="font-size: 20px" class="el-icon-user"></i
              ></template>
            </el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input
              type="password"
              name="password"
              v-model="form.password"
              autocomplete="on"
              placeholder="请输入密码"
            >
              <template slot="prepend"
                ><i style="font-size: 20px" class="el-icon-key"></i
              ></template>
            </el-input>
          </el-form-item>
          <el-form-item>
            <el-button
              style="width: 100%"
              type="primary"
              @click="onLogin"
              :loading="loading"
              >登录</el-button
            >
          </el-form-item>
        </el-form>
      </div>
    </el-card>
  </div>
</template>

<script>
import { reactive, ref } from "@vue/composition-api";
import { useUserStore } from "@/store/user";
import router from "../../router";
export default {
  setup() {
    const userStore = useUserStore();
    const form = reactive({
      username: "",
      password: "",
    });
    const loading = ref(false);
    const loginRules = {
      username: [{ required: true, message: "请输入账户", trigger: "blur" }],
      password: [{ required: true, message: "请输入密码", trigger: "blur" }],
    };

    function onLogin() {
      loading.value = true;
      userStore.login(form).then(() => {
        loading.value = false;
        router.push({
          name: "index",
        });
      });
    }

    return {
      form,
      onLogin,
      loginRules,
      loading,
    };
  },
};
</script>

<style scoped>
</style>

<!-- <template>
  <div class="login-page"></div>
</template>
  
  <script>
export default {
  name: "Login",
  data() {
    return {
      loading: false,
      form: {
        userName: "",
        passWord: "",
      },
      loginRules: {
        userName: [{ required: true, message: "请输入账户", trigger: "blur" }],
        passWord: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  methods: {
    handleLogin() {
      this.$refs.loginForm
        .validate()
        .then(() => {
          this.loading = true;

          //模拟异步请求后台接口 登录操作
          setTimeout(() => {
            this.$router.push("/home");
            this.loading = false;
          }, 1000);
        })
        .catch((error) => {
          this.$message({
            message: "输入错误！",
            type: "warning",
          });
        });
    },
  },
};
</script> -->
  
  <style scoped>
/* .login-page {
  background-image: linear-gradient(180deg, #2af598 0%, #009efd 100%);
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
} */

.login-title {
  font-size: 20px;
}

.box-card {
  width: 375px;
}
</style>
  